This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
feat(rome_js_analyzer): noSelfAssignment
rule
#4091
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Part of #3980
This PR starts the implementation of the
noSelfAssignment
rule. The rule is quite lengthy so I had to stop at sont toless too much meat to the fire.The implementation of this is quite different from the ESLint one. The ESLint implementation is "simple" but has various pitfalls:
To avoid this memory pressure I had to come up with something, so implementation relies on:
The gist of the implementation is the following:
JsAssignmentExpression
is broken in two arms: left-arm and right-arm, which is calledAnyJsAssignmentLike
a = a
, it returns the pair of(a, a)
, but in a code like[a, 1, b] = [a, c, b]
, the first iteration returns(a, a)
but the second iteration returnNone
because1
andc
are not similar (their AST nodes are different), and the third returns(b,b)
The ad-hoc iterator works this way:
.next()
on both iterators; both items need to exist and need to be "similar" (there are various matches to check if they are similar), failing to adhere to these two requirements will continue to the next item[{a, b}, c] = [{a, b}, c]
, we stop the current iteration, save it into a queue, and we start a new one. We resume the previous one when we "drain" this latest iteration.This implementation doesn't cover:
a['b']
Test Plan
The tests are taken from the test suite of ESLint
Documentation